import Vue from "vue"
import Route from "vue-router"
import Home from "@/view/Home.vue"
import SpuIndex from "@/view/Spu/SpuIndex.vue"
import MenuIndex from "@/view/Menu/MenuIndex.vue"
import UserIndex from "@/view/User/UserList.vue"
import LoginIndex from "@/view/Login/LoginList.vue"
import DictIndex from "@/view/Dictinfo/infolist.vue"
import DicttypeIndex from "@/view/Dicttype/typelist.vue"


Vue.use(Route)

deRepeat();

// 避免重复导航
function deRepeat() {
	// 获取原型对象push函数
	const originalPush = Route.prototype.push

	// 获取原型对象replace函数
	const originalReplace = Route.prototype.replace

	// 修改原型对象中的push函数
	Route.prototype.push = function push(location) {
		return originalPush.call(this, location).catch(err => err)
	}

	// 修改原型对象中的replace函数
	Route.prototype.replace = function replace(location) {
		return originalReplace.call(this, location).catch(err => err)
	}
}


const routes = [{
	path: '/',
	redirect: '/home'
},
{
	path: '/login',
	name:'login',
	component: () => import("@/view/Login.vue")
},
{
	path: '/home',
	component: Home,
	children: [
		{
			path:'/order',
			name:'order',
			component: () => import("@/view/Order/order.vue")
		},
		{
			path: '/User',
			name: "User",
			component: UserIndex
		},
		{
			path: '/Menu',
			name: 'menu',
			component: () => import("@/view/Menu/MenuIndex.vue")
		},
		{
			path: "/Shop/Material",
			name: "material",
			component: () => import("@/view/Material/MaterialList.vue")

		},
		{
			path: '/shop',
			name: "spu",
			component: SpuIndex,
			redirect: '/shopList',
			children: [{
				path: '/shopList',
				name: 'shopList',
				component: () => import("@/view/Spu/SpuList.vue")
			},
			{
				path: '/shopAdd',
				name: 'shopAdd',
				component: () => import("@/view/Spu/SpuAdd.vue")
			},
			{
			path:'/dict/dictinfo',
				name:"dict",
				component:DictIndex
			},
			{
			path:'/dict/dicttype',
				name:"dict",
				component:DicttypeIndex
			}
			]
		},
		{
			path: '/role',
			name: 'role',
			component: () => import("@/view/RoleInfo/Rolelist.vue")
		},
		{
			path: '/shop/template',
			name: 'temp',
			component: () => import("@/view/Template/Templatelist.vue")
		},
		{
			path: '/loginInfo',
			name: "loginInfo",
			component: LoginIndex
		}
	]
}
]



export default new Route({
	mode: "history",
	routes: routes
})